<?php

namespace app\services\pay;


use Alipay\EasySDK\Kernel\Factory;
use Alipay\EasySDK\Kernel\Config;

/**
 * 支付宝支付中间件
 */
class WxpayService
{
    public function pay($amount, $openID, $orderSn, $body, $subject, $notifyUrl, $orderType){
        require '../extend/AlipaySDK/aop/AopClient.php';
        require_once '../extend/AlipaySDK/aop/request/AlipayTradeAppPayRequest.php';
        $aop = new \AopClient;
        $aop->gatewayUrl = "https://openapi.alipay.com/gateway.do";
        $aop->appId = "2021004143623046";
        $aop->rsaPrivateKey = 'MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCF4OWO1Fp/aR1+P7qeIf67gV4eFl+iBd2g92w8W4L3qhANexkTVNZRq6DH+cWJtwab1OV0dkVKvPX9C3NNCT25T088MfeXJ0tAm8FjOjfTfEhdalGfDKI733ESZIHRPKHqskJmhsFPz/VkSPPnvzhSXAfZJdKLIK9wmx1rmvhTQeoAb2eeixzCmBuIRGI1JBC018ufrwa47zqi8Ngm5hWuhp850WGfEedgY0L9D/A4aG91GVy1LZfjItS9LvXNr59FuFuUWy2LVizLbj0ATtHfMSHparFpadl5b17AnwBqjxdMmPtlcs3VjXv5pxymfRhtvlKjvHI+1N0+1TiBrw2nAgMBAAECggEAbFsZESAYWvUF1O/ZqDFVjgdn2Kw9HNLojWaUaMmcV72CHpcaNYY9rH5ftFsZIZxMMgX+7OLotFP6OKNy38/x8DEbrVm3zdQU2Sb3P8uX8YiuvUTW6Qb9q73uM3e7hlEvr9g1W+wHPATR1SgimNgwyqAIDh3Jqad7t4UkK7qS8DbFDSwA3+3sAiEqDNR3NzWpVE9JdD24/3BvIGXu42GeLkrGLyVffN2BdNtXOEJpOIcN+onIyZUA9WBBSUbe4Mgr64iAgk8tpb4v1TnAK78gwPrUUbQErRKqYcIDUjedP/5bJaVRZTiFaAUph0Yug7l1Yq1i3l/shUE0I6Dwfo8dOQKBgQDL6wHwF3nEhfKwQqZqs6fD44CW678FFATNTNaLPCV8LTJMT7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FoFVctJvCB85Tm+3WuHTOPXwE1/M+94d2vEDWdWC3/aEFS/xO0kt7GQNkr4uGqtN3u/B4CBhaJLYck4iPbzRSCgagTnuaiw5wiiuaoJ/UHu486Iobql3lhclsEWibhMZ2qMJuT3q3vC7sCc/pmu29bsFCT4bbHgwm4JwIDAQAB';
        $aop->format = "json";
        $aop->charset = "UTF-8";
        $aop->signType = "RSA2";
//实例化具体API对应的request类,类名称和接口名称对应,当前调用接口名称：alipay.trade.app.pay
        $request = new \AlipayTradeAppPayRequest();
//SDK已经封装掉了公共参数，这里只需要传入业务参数
        $bizcontent = "{\"body\":\"我是测试数据\","
            . "\"subject\": \"App支付测试\","
            . "\"out_trade_no\": \"20170125test01\","
            . "\"timeout_express\": \"30m\","
            . "\"total_amount\": \"0.01\","
            . "\"product_code\":\"QUICK_MSECURITY_PAY\""
            . "}";
        $request->setNotifyUrl(request()->domain() . '/api/Notify/aliPayNotify');
        $request->setBizContent($bizcontent);
//这里和普通的接口调用不同，使用的是sdkExecute
        $response = $aop->sdkExecute($request);
//htmlspecialchars是为了输出到页面时防止被浏览器将关键参数html转义，实际打印到日志以及http传输不会有这个问题
        $result['orderInfo'] = htmlspecialchars($response);
        echo $response;
        echo '<br>';
        echo $result['orderInfo'];
    }

}